package cn.bytecollege.admin.filter;

import cn.bytecollege.common.constant.Resource;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@WebFilter(filterName = "ResourceFilter",urlPatterns = "/admin/static/*")
public class ResourceFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
    }

    public void destroy(){
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req = (HttpServletRequest) request;
        //获取请求资源的路径
        String uri = req.getRequestURI();
        //将请求转发至对应的目录
        request.getRequestDispatcher(Resource.PAGE_LOCATION + uri).forward(request, response);
    }
}
